package io.renren.modules.project.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.modules.project.entity.NotificationEntity;
import io.renren.modules.project.service.NotificationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by LDC on 2018/11/27.
 */

@RestController
@RequestMapping("/generator/notification")
public class NotificationController {
    @Autowired
    private NotificationService notificationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:notification:list")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<NotificationEntity> notificationList = notificationService.queryList(query);
        int total = notificationService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(notificationList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("generator:notification:info")
    public R info(@PathVariable("id") String id){
        NotificationEntity notification = notificationService.queryObject(id);

        return R.ok().put("notification", notification);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:notification:save")
    public R save(@RequestBody NotificationEntity notification){
        notificationService.save(notification);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:notification:update")
    public R update(@RequestBody NotificationEntity notification){
        notificationService.update(notification);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:notification:delete")
    public R delete(@RequestBody String[] ids){
        notificationService.deleteBatch(ids);

        return R.ok();
    }

}
